<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateActivities extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('activities', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name',256)->comment('活动名称');
            $table->integer('start_time')->comment('开始时间');
            $table->integer('end_time')->comment('结束时间');
            $table->string('banner',512)->comment('banner图片链接')->default('');
            $table->text('rules')->comment('活动规则');
            $table->text('purpose')->comment('活动营销目标');
            $table->tinyInteger('filter_type')->comment('活动对象类型,1渠道,2群体');
            $table->text('user_filter')->comment('活动对象名称列表,以逗号分隔,用于列表显示');
            $table->text('ignores')->comment('排除的用户id列表,用逗号分隔');
            $table->text('rewards')->comment('奖池名称列表,以逗号分隔,用于列表显示');
            $table->timestamps();
        });
        Schema::create('activity_user_filters',function(Blueprint $table){
            $table->increments('id');
            $table->integer('activity_id')->comment('活动id');
            $table->integer('filter_id')->comment('活动对象id(渠道或群体id)');
            $table->timestamps();
        });
        Schema::create('user_groups',function(Blueprint $table){
            $table->increments('id');
            $table->string('name',256)->comment('群体名称');
            $table->text('description')->comment('群体描述');
            $table->text('conditions')->comment('条件json字符串');
            $table->timestamps();
        });
        Schema::create('activity_rewards',function(Blueprint $table){
            $table->increments('id');
            $table->integer('activity_id')->comment('活动id');
            $table->integer('package_id')->comment('奖池id');
            $table->integer('behavior')->comment('行为id');
            $table->timestamps();
        });
        Schema::create('reward_packages',function(Blueprint $table){
            $table->increments('id');
            $table->string('name',256)->comment('奖池名称');
            $table->integer('start_time')->comment('生效时间');
            $table->integer('end_time')->comment('失效时间');
            $table->text('items')->comment('奖池奖品json字符串');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('activities');
        Schema::drop('activity_user_filters');
        Schema::drop('user_groups');
        Schema::drop('activity_rewards');
        Schema::drop('reward_packages');
    }
}
